import Vue from 'vue'
import {
    showTip,
	showModalWithCloseButton
} from '../../api/framework/api.js'
import oaconfig from './config.js'
import {
    request
} from '../../api/framework/request.js'
  //公共函数  2020/09/10
export default {
    /*
      获取流程相关讯息
      wfSession 传入工作流相关信息
     */
    getWorkFlowData(wfSession) {
        let FundSatrt = -1; //流程状态 -1 创建
        let actionType = null; //操作 0-创建
        let billNo = null; //单据编号
        if (wfSession.status != -1) {
            billNo = wfSession.business_no
        }
        if (wfSession.actionType) {
            actionType = wfSession.actionType
        }
        if (wfSession.status) {
            FundSatrt = wfSession.status
        }
        return {
            FundSatrt: FundSatrt,
            actionType: actionType,
            billNo: billNo
        }

    },


    // _this.$api.showTip(uploadData.msg);
    /**
     * 判断是否是起草、暂存
     * @param {Object} processData 页面单据及状态信息
     * @param {Object} data 工作流数据
     * @param {Object} rowData 页面数据
     * @param {Object} callback fun
     */
    selectDraft(processData, subJson, rowData, callback) {
        var subJson1 = eval("(" + decodeURIComponent(subJson) + ")");
        subJson1.tenancyId = processData.objVue.$oaconfig.lesseeCode
        if (subJson1.actiontype == "13" || subJson1.actiontype == "14") {
            var prefix = "";
            if (subJson1.actiontype == "13") {
                prefix = processData.prefix;
            }

            var objdata = {
                prefix: prefix,
                tenancyId: processData.objVue.$oaconfig.lesseeCode,
                subJson: encodeURIComponent(top.JSON.stringify(subJson1)),
                jsonData: JSON.stringify(rowData)
            }
            // objdata.subJson.tenancyId = processData.objVue.$oaconfig.lesseeCode
            processData.objVue.$lyRequest.requestConfig.header = {
                'Accept': "application/json, text/javascript, */*; q=0.01",
                "Content-Type": "application/x-www-form-urlencoded;charset=utf-8;"
            };
            processData.objVue.$lyRequest.post("/ly/mp/busicen/cm/basedata/draft/draft.do", objdata).then(result => {
                if (result.data && result.data.result == '1') {
                    callback("1");
                } else {
                    callback("0");
                }
            });
            processData.objVue.$lyRequest.requestConfig.header = {
                'Accept': "application/json, text/javascript, */*; q=0.01"
            };
        } else {

            callback(encodeURIComponent(top.JSON.stringify(subJson1)));
        }
    },
    /*
     * 提交流程，保存业务数据，修改流程状态
     * 流程状态为：发起，暂存，审核
     * @param processData: odj，流程相关数据，记录流程当前状态，流程访问的接口及控制 必含字段：url_update ,url_add，url_upStatus
     * @param data: odj，用于提交给后台做业务逻辑判断，包含subJson，主表及明细表数据
     * @param callback
     */
    submit(processData, data, subJson, callback) {
        //流程操作
        if (!processData.url_update || !processData.url_add || !processData.url_upStatus) {
            alert("你是不是忘了写url_update，url_add，url_upStatus参数了");
            return;
        }
        let busiTripNo = processData.billNo;
        let subJson1 = eval("(" + decodeURIComponent(subJson) + ")");
        subJson1.tenancyId = processData.objVue.$oaconfig.lesseeCode;
        subJson= encodeURIComponent(top.JSON.stringify(subJson1));
        data.subJson= subJson;
        if (processData.billNo && processData.billNo != null) {
            //修改
            if (processData.actionType == "2" || processData.isUpdate ||processData.actionType == "14" ||processData.actionType == null) {
                processData.isEdit = true; //调用修改接口
                processData.objVue.$lyRequest.post(processData.url_update, data).then(result => {
                    if (result.data && result.data.result == '1') {
                        if(result.data.rows&&result.data.rows.busiTripNo){
                            busiTripNo= result.data.rows.busiTripNo;
                            if(processData.showMain == '1' || processData.showMain == '2'){
                                if(data.changeNo){
                                    busiTripNo = data.changeNo
                                }else{
                                    busiTripNo =  result.data.rows.changeNo
                                }
                            }

                            if(processData.url_upStatus.indexOf('change')!=-1){
                                busiTripNo= result.data.rows.reimNo;
                            }
                        }
                        saveMVO(busiTripNo, processData, data);
                    } else { // 调用接口失败情况
                        showTip(result.data.msg);
                        callback(false);
                    }
                });
            } else {
                processData.isEdit = false; //根据条件设置该值
                saveMVO(busiTripNo, processData, data);
            }
        } else {
            //新增
            processData.isEdit = true; //根据条件设置该值
            processData.objVue.$lyRequest.post(processData.url_add, data).then(result => {
                if (result.data && result.data.result == '1') {
                    busiTripNo= result.data.rows.busiTripNo;
                    if(processData.url_upStatus.indexOf('change')!=-1){
                        busiTripNo= result.data.rows.reimNo;
                    }
                    saveMVO(busiTripNo, processData, data);
                } else { // 调用接口失败情况
                    showTip(result.data.msg);
                    callback(false);
                }
            });
        }

        function saveMVO(busiTripNo, processData, data) {
            var actionType = processData.actionType;
            processData.objVue.$lyRequest.requestConfig.header = {
                'Accept': "application/json, text/javascript, */*; q=0.01",
                "Content-Type": "application/x-www-form-urlencoded;charset=utf-8;"
            };
            if (busiTripNo != null && busiTripNo != "") {
                let subJson1 = eval("(" + decodeURIComponent(subJson) + ")");
                subJson1.business_no = busiTripNo;
                subJson= encodeURIComponent(top.JSON.stringify(subJson1));
                data.subJson= subJson;
            }
            let formData={
                tenancyId : processData.objVue.$oaconfig.lesseeCode
            };
            var keyArr = Object.keys(data);
            for (let n in data) {
            	let type = typeof data[n];
                if (type == 'boolean' || type == 'string') {
                    formData[n]= data[n];
                }
            }
            //工作流接口
            processData.objVue.$lyRequest.post("/mp/wfengine/step/handleWFAction.do", formData).then(res => {
                if (res.data.result == '1') {
                    let param = {};
                    if(processData.url_upStatus.indexOf('change')!=-1){
                        param={
                            reimNo: busiTripNo,
                            tenancyId: processData.objVue.$oaconfig.lesseeCode,
                            subJson: data.subJson
                        };
                    }else{
                        param={
                            busiTripNo: busiTripNo,
                            tenancyId: processData.objVue.$oaconfig.lesseeCode,
                            subJson: data.subJson
                        };
                    }
                    //修改单据状态

                    processData.objVue.$lyRequest.requestConfig.header = {
                        'Accept': "application/json, text/javascript, */*; q=0.01",
                        "Content-Type": "application/x-www-form-urlencoded;charset=utf-8;"
                    };
                    processData.objVue.$lyRequest.post(processData.url_upStatus, param).then(
                        result => {
                            if (result.data && result.data.result == '1') {
                                callback(true, busiTripNo);
                            } else { // 调用接口失败情况
                                showTip(result.data.msg);
                                callback(false);
                            }
                        });
                    processData.objVue.$lyRequest.requestConfig.header = {
                        'Accept': "application/json, text/javascript, */*; q=0.01"
                    };

                }else{
                    showTip(res.data.msg);
                    callback(false);
                }
            })
            processData.objVue.$lyRequest.requestConfig.header = {
                'Accept': "application/json, text/javascript, */*; q=0.01"
            };
        }
    },
    /**
     * objdata:{
     * objVue:this
     * 	billNo:单号
     *  queryurl:业务查询接口
     * }
     */
    //查询是否有暂存数据
    draft(objdata, callback) {
        let billno = {
            billNo: objdata.billNo,
            tenancyId: objdata.objVue.$oaconfig.lesseeCode
        }
        objdata.objVue.$lyRequest.get('/ly/mp/busicen/cm/basedata/draft/selectOne.do', billno).then(resultdata => {
            if (resultdata.data.result == "1") {
                if (resultdata.data.rows.status == "0") { //有暂存数据
                    //console.log(resultdata.data.rows);
                    let _data = JSON.parse(resultdata.data.rows.jsonData);
                    var rowsdata = {
                        rows: _data,
                        status: resultdata.data.rows.status
                    };
                    callback(rowsdata);
                } else {
                    //业务数据查询
                    objdata.objVue.$lyRequest.get(objdata.queryurl, billno).then(result => {
                        if (result.data && result.data.result == "1") {
                            callback(result.data);
                        } else {
                            showTip(result.data.msg);
                            callback(null);
                        }
                    })
                }
            } else {
                showTip(resultdata.data.msg);
                callback(null);
            }
        });
    },
    /**
     * actionType: 13：起草；14：暂存；6：驳回；7：作废
     * @param {Object} actionType
     */
    selectActionType(actionType) {
        if (actionType != "13" && actionType != "14" && actionType != "6" && actionType != "7") {
            return true;
        } else {
            return false;
        }
    },

    /**
     * 金额千分位
     * @param {Object} num
     */
    // thousand(num) {
    //     var amtNum = "" == num ? "" : num.toString().replace(/,/g, "");
    //     var amtStr = (Number(amtNum).toFixed(2) + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
    //     return "NaN" == amtStr ? "0.00" : amtStr;
    // },


    /**
     * @type {string} 日期1 日期2
     * @description 日期对比函数
     */
    dateCompare(time1, time2) {
        var reg = /[^\d]+/;
        var arr1 = time1.split(reg);
        var arr2 = time2.split(reg);
        //只校验年月日
        var d1 = new Date(arr1[0], (Number(arr1[1]) - 1) + "", arr1[2]).getTime();
        var d2 = new Date(arr2[0], (Number(arr2[1]) - 1) + "", arr2[2]).getTime();
        //校验年月日 时分秒
        // var d1 = new Date(arr1[0], (Number(arr1[1]) - 1) + "", arr1[2],arr1[3],arr1[4],arr1[5]).getTime();
        // var d2 = new Date(arr2[0], (Number(arr2[1]) - 1) + "", arr2[2],arr2[3],arr2[4],arr2[5]).getTime();
        return d1 - d2;
    },

    /*
        生成随机字符转
        type 类型

    */
    RandomNumBoth(type) {
        const Max = 99999;
        const Min = 10000;
        const Range = Max - Min;
        const Rand = Math.random();
        const num = Min + Math.round(Rand * Range);
        const DateTime = new Date()
        if (type) {
            return type + num + DateTime.getTime();
        } else {
            return num + DateTime.getTime();
        }

    },

    /*
        日期
        type 开始 / 结束
    */
    getDate(type) {
        const date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();

        let Hour = date.getHours();
        let minute = date.getMinutes();
        let second = date.getSeconds();
        if (type === 'start') {
            year = year - 60;
        } else if (type === 'end') {
            year = year + 2;
        }
        month = month > 9 ? month : '0' + month;
        day = day > 9 ? day : '0' + day;

        //     Hour = Hour > 9 ? Hour : '0' + Hour;
        //     minute = minute > 9 ? minute : '0' + minute;
        //     second = second > 9 ? second : '0' + second;

        return `${year}-${month}-${day}` + ' ' + '00' + ':' + '00' + ':' + '00';
    },
	getNewDate(isZero, type) {
	    const currDate = new Date()
		const currYear = currDate.getFullYear()
		let currMonth = currDate.getMonth() + 1
		let currDay = currDate.getDate()
		let currHoure = currDate.getHours()
		let currMin = currDate.getMinutes()
		let currSec = currDate.getSeconds()
		if (isZero) { // 需要补零
		  currMonth = currMonth < 10 ? '0' + currMonth : currMonth
		  currDay = currDay < 10 ? '0' + currDay : currDay
		  currHoure = currHoure < 10 ? '0' + currHoure : currHoure
		  currMin = currMin < 10 ? '0' + currMin : currMin
		  currSec = currSec < 10 ? '0' + currSec : currSec
		}
		let _retData = {}
		switch (type.toLocaleUpperCase()) {
		  case 'Y':
			_retData = {
			  retOne: currYear + '年',
			  retTwo: currYear
			}
			break
		  case 'M':
			_retData = {
			  retOne: currMonth + '月',
			  retTwo: currMonth
			}
			break
		  case 'D':
			_retData = {
			  retOne: currDay
			}
			break
		  case 'YM':
			_retData = {
			  retOne: currYear + '年' + currMonth + '月',
			  retTwo: currYear + '-' + currMonth,
			  retThree: currYear + '/' + currMonth
			}
			break
		  case 'YMD':
			_retData = {
			  retOne: currYear + '年' + currMonth + '月' + currDay + '日',
			  retTwo: currYear + '-' + currMonth + '-' + currDay,
			  retThree: currYear + '/' + currMonth + '/' + currDay
			}
			break
		  case 'YMDH':
			_retData = {
			  retOne: currYear + '年' + currMonth + '月' + currDay + '日 ' + currHoure + '时',
			  retTwo: currYear + '-' + currMonth + '-' + currDay + ' ' + currHoure,
			  retThree: currYear + '/' + currMonth + '/' + currDay + ' ' + currHoure
			}
			break
		  case 'YMDHMS':
			_retData = {
			  retOne: currYear + '年' + currMonth + '月' + currDay + '日 ' + currHoure + '时' + currMin + '分' + currSec + '秒',
			  retTwo: currYear + '-' + currMonth + '-' + currDay + ' ' + currHoure + ':' + currMin + ':' + currSec,
			  retThree: currYear + '/' + currMonth + '/' + currDay + ' ' + currHoure + ':' + currMin + ':' + currSec
			}
			break
		  default:
			_retData = {
			  retOne: currDate
			}
			break
		}
		return _retData
	},
    /*
     金额千分位处理
     num 传入金额(Number)
     */
    thousand(num) {
        if(isNaN(num)){
            return '0.00'
        }
        return (Number(num).toFixed(2) + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
    },

    /*
     H5图片压缩
     file 文件信息
     callback 回调
     */
    compressFile(file, callback) {
        if(file.size > 10240000){ //不能上传超过10M的图片
            showTip('不能上传超过10M的图片！')
            return
        }
		let index = 1;
		/*******************START 记录同一文件重复识别，默认认为识别失败 调整压缩倍数    *******************/
		let isok = false;//第二次识别则为true/第一次识别false
		uni.getStorage({
		    key: 'OcrRecord',
		    success: function (res) {
				if(file.name == res.data.name){
					// debugger
					isok = true
					if(res.data.key == 1){
						index = 2
						let OcrRecord = {name:file.name,key:2}
						uni.setStorage({
						    key: 'OcrRecord',
						    data: OcrRecord,
						    success: function () {
						        console.log('success');
						    }
						});
						// 调低压缩频率
					}else if(res.data.key == 2){
						// 不压缩
						index = 3
						let OcrRecord = {name:file.name,key:3}
						uni.setStorage({
						    key: 'OcrRecord',
						    data: OcrRecord,
						    success: function () {
						        console.log('success');
						    }
						});
					}
				}
		    }
		});

		//初始化缓存（第一次识别）
		if(!isok){
			let OcrRecord = {name:file.name,key:1}
			uni.setStorage({
			    key: 'OcrRecord',
			    data: OcrRecord,
			    success: function () {
			        console.log('success');
			    }
			});
		}
		/*******************END 记录同一文件重复识别，默认认为识别失败 调整压缩倍数    *******************/
        let fileObj = file;
        //判断大于512KB == 524288字节 则需要压缩图片
		// 1048576
        let fileSuffix = fileObj.name.split(".")[fileObj.name.split(".").length - 1];

        if (fileObj.size > 524288 &&
        ( fileSuffix.toUpperCase() == 'PNG'
        || fileSuffix.toUpperCase() == 'JPEG'
        || fileSuffix.toUpperCase() == 'JPG')) {
            let reader = new FileReader();
            reader.readAsDataURL(fileObj); //转base64
            reader.onload = function(e) {
                let image = new Image(); //新建一个img标签（还没嵌入DOM节点)
                image.src = e.target.result;
                image.onload = function() {
					let width,height;

					if (fileObj.size > 1048576 && fileObj.size < 2548576) {
						width = 2//压缩后图片的大小
						height = 2
					}else if (fileObj.size > 2548576 && fileObj.size < 5242880) {
						width = 3//压缩后图片的大小
						height = 3
					}else if(fileObj.size >= 5242880){
						width = 4 //压缩后图片的大小
						height = 4
					}else {
						width = 2 //压缩后图片的大小
						height = 2
					}


					/*******************START 记录同一文件重复识别，默认认为识别失败 调整压缩倍数    *******************/
					if(index == 2){
						width = 2 //压缩后图片的大小
						height = 2
					}else if(index == 3){
						width = 1 //压缩后图片的大小
						height =  1
					}
					/*******************END 记录同一文件重复识别，默认认为识别失败 调整压缩倍数    *******************/
                    let canvas = document.createElement('canvas'), // 新建canvas
                        context = canvas.getContext('2d'),

                        imageWidth = image.width / width, //压缩后图片的大小
                        imageHeight = image.height / height,
                        data = '';
                    canvas.width = imageWidth;
                    canvas.height = imageHeight;
					console.log(canvas)
                    context.drawImage(image, 0, 0, imageWidth, imageHeight);
                    data = canvas.toDataURL('image/jpeg'); // 输出压缩后的base64
                    let arr = data.split(','),
                        mime = arr[0].match(/:(.*?);/)[1], // 转成blob
                        bstr = atob(arr[1]),
                        n = bstr.length,
                        u8arr = new Uint8Array(n);
                    while (n--) {
                        u8arr[n] = bstr.charCodeAt(n);
                    }
                    let files = new window.File([new Blob([u8arr], {
                        type: mime
                    })], file.name, {
                        type: 'image/jpeg'
                    }); // 转成file
                    callback(files); // 回调
                };
            };
        } else {
            callback(fileObj);
        }
    },
    /*
    获取当前导航栏地址参数
    */
    getlocationhref(str) {
        let $_REQUEST = new Object,
            data = str.slice(str.indexOf("/?") + 1, str.length - 1), // 截取数据字符串
            aParams = data.substr(1).split("&"); // 将数据字符串表现为数组
        for (let i = 0; i < aParams.length; i++) {
            let aParam = aParams[i].split("="); // 数据属性与数值分离
            $_REQUEST[aParam[0]] = aParam[1] // 使用属性括号进行属性赋值
        }
        return $_REQUEST;
    },
    /*
    非空验证
    arr 传入数组
    */
    verifyEmpty(arr) {
        for (let i = 0; i < arr.length; i++) {
            if (!arr[i].inspect) {
                showTip(arr[i].msg);
                return false;
            }
        }
        return true;
    },
    /*
    租户id
    获取本地缓存租户信息
    _this 当前页面this指向
     */
    getTenancyID(_this) {
        uni.getStorage({
            key: 'TENANCY_ID',
            success: function(res) {
                _this.$oaconfig.lesseeCode = res.data;
            }
        });
        uni.getStorage({
            key: 'TENANCY_Name',
            success: function(res) {
                _this.$oaconfig.lesseeName = res.data;
            }
        });
    },
    /*
    获取代办数量
    _this 当前使用页面this指向
    */
    getdaiban(_this,callback) {
        let param = {
            pt: 5,
            pagesize: 10,
            pageindex: 1,
            sort: 'desc',
            sortfield: 'INITIATE_DATETIME',
            qmode: 0,
            cquery: '',
            pname: '',
            businessno: '',
            ptype: '',
            pstarter: '',
            lasthandler: '',
            extprov1: '',
            starttime: '',
            endtime: '',
            p_kind_guid: '',
            p_module_guid: '',
            tenancyId: _this.$oaconfig.lesseeCode,
        }

        _this.$lyRequest.requestConfig.header = {
            'Accept': "application/json, text/javascript, */*; q=0.01",
            "Content-Type": "application/x-www-form-urlencoded;charset=utf-8;"
        };
        _this.$lyRequest.get('/mp/wfengine/mytask/pending.do', param).then(
            result => {
                if (result.data && result.data.result == '1') {
                    let records = result.data.records
                    if (records > 100) {
                        records = 99 + '+'
                    } else if (records) {
                        records = JSON.stringify(result.data.records)
                    }
                    /* if (records) {
                        uni.setTabBarBadge({
                            index: 1,
                            text: records
                        })
                    } else {
                        uni.removeTabBarBadge({
                            index: 1,
                            text: records
                        })
                    } */
                    if(callback) callback(result.data);

                }else{
                    if(callback) callback('');
                }
            });
        _this.$lyRequest.requestConfig.header = {
            'Accept': "application/json, text/javascript, */*; q=0.01"
        };
    },

    /*
        OCR识别公共函数
        File 文件流信息
        _this 当前this指向
        callback 回调
    */

    uploadFile(File, _this, callback, ) {
        let formData = {
            token: _this.$api.getToken(),
            lesseeCode: _this.$oaconfig.lesseeCode,
            isAuthenticity: true //是否验真
        };
        uni.uploadFile({
            url: _this.$config.domain + '/ly/mp/busicen/cm/invoiceInfo/newDistinguish.do',
            // url: _this.$config.domain + '/ly/mp/busicen/cm/buInvoiceInfo/distinguish.do',
            file: File,
            name: 'uploadFile',
            fileType: 'FP',
            formData: formData,
            success: uploadFileRes => {
                const uploadData = JSON.parse(uploadFileRes.data);
                // 识别成功
                if (uploadData && uploadData.result == 1) {
					//清楚Ocr同一文件多次识别失败记录
					uni.removeStorage({
					    key: 'OcrRecord',
					    success: function (res) {
					        console.log('success');
					    }
					});
                    callback(uploadData)
                    //识别重复
                } else if (uploadData && uploadData.result == 2) {
					//清楚Ocr同一文件多次识别失败记录
					uni.removeStorage({
					    key: 'OcrRecord',
					    success: function (res) {
					        console.log('success');
					    }
					});
                    callback(uploadData)
                } else {
                    callback(uploadData)
                }
            },
            fail: err => {
                callback(false)
            }
        });
    },


    uploadFileOCR(File, _this,data, callback) {
        let formData = {
            token: _this.$api.getToken(),
            tenancyId: _this.$oaconfig.lesseeCode,
            isAuthenticity: true, //是否验真
            invoiceCodeList:null,//发票集合
            updateControlId:data.updateControlId,
            folderTypeCode:data.folderTypeCode,
            folderName:data.folderName,
            folderTitle:data.folderTitle,
            folderCode:data.folderCode,
            folderStartDate:data.folderStartDate,
            folderEndDate:data.folderEndDate,
            type:'0' //type 0: ocr扫描 ,1:selected选择已有 ,2:add手工填写

        };
        uni.uploadFile({
            url: _this.$config.domain + '/ly/mp/busicen/cm/billfold/addOCRDetail.do',
            // url: _this.$config.domain + '/ly/mp/busicen/cm/buInvoiceInfo/distinguish.do',
            file: File,
            name: 'uploadFile',
            fileType: 'FP',
            formData: formData,
            success: uploadFileRes => {
                const uploadData = JSON.parse(uploadFileRes.data);

                // 识别成功
                if (uploadData && uploadData.result == 1) {
					//清楚Ocr同一文件多次识别失败记录
					uni.removeStorage({
					    key: 'OcrRecord',
					    success: function (res) {
					        console.log('success');
					    }
					});
                    callback(uploadData)
                    //识别重复
                } else if (uploadData && uploadData.result == 2) {
					//清楚Ocr同一文件多次识别失败记录
					uni.removeStorage({
					    key: 'OcrRecord',
					    success: function (res) {
					        console.log('success');
					    }
					});
                    callback(uploadData)
                } else {
                    callback(uploadData)
                }
            },
            fail: err => {
                callback(false)
            }
        });
    },
	//登录时使用
	getappuserInfo(_this,callback){
	    _this.$lyRequest.get('/ly/mp/busicen/cm/basedata/sysUser/appUserInfo.do', {}).then(result => {
	        if (result.data && result.data.result == '1') {
	            callback(result)
	        } else {
	            callback(result)
	            _this.$api.showModalWithCloseButton('获取用户信息失败');
	        }
	    });
	},
    /*
    获取用户信息
    */
    getuserInfo(_this,callback){
        _this.$lyRequest.get('/ly/mp/busicen/cm/basedata/sysUser/userInfo.do', {}).then(result => {
            if (result.data && result.data.result == '1') {
                callback(result)
            } else {
                callback(result)
                _this.$api.showModalWithCloseButton('获取用户信息失败');
            }
        });
    },
    //日期拼接转换
    dateTime(value,type) {
        const date = new Date(value);
        const DateTime = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
        let Hour = DateTime.getHours();
        let minute = DateTime.getMinutes();
        let second = DateTime.getSeconds();

        month = month > 9 ? month : '0' + month;
        day = day > 9 ? day : '0' + day;
        Hour = Hour > 9 ? Hour : '0' + Hour;
        minute = minute > 9 ? minute : '0' + minute;
        second = second > 9 ? second : '0' + second;
		if(!type){
			return value.trim().split(' ')[0] + ' ' + Hour + ':' + minute + ':' + second;
		}
		if(type == 'startDate'){
			return value.trim().split(' ')[0] + ' ' + '00' + ':' + '00' + ':' + '00';
		}else if(type == 'endDate'){
			return value.trim().split(' ')[0] + ' ' + '23' + ':' + '59' + ':' + '59';
		}

    },
	isWechat() {
		var ua = window.navigator.userAgent.toLowerCase();
		if (ua.match(/micromessenger/i) == 'micromessenger') {
			//是微信客户端
			return true;
		} else {
			//不是微信客户端
			return false;
		}
	},
	WechatInvoice(data,that,callback){

		if(data){
			// if(data.json.choose_invoce_info !=="[]"){
			// 	that.$api.showModalWithCloseButton('暂无发票可导入');
			// 	return;
			// }

            let url = data.folderCode?'/ly/mp/busicen/cm/billfold/addWeiXinDetail.do':'/ly/mp/busicen/cm/wxInvoice/getInvoiceInfo.do';

			uni.showLoading({
				title:"正在导入发票..."
			})
			that.$lyRequest.post(url, data).then(result => {
			    if (result.data && result.data.result == '1') {
			        callback(result)
			    } else {
			        callback(result)
			    }
				uni.hideLoading()
			});
		}
	},
	//时间段
	timeSlot(){
		let now = new Date();
		let hour = now.getHours();
		let obj = {
			theme:'',
			Hellogreetings:''
		}
		let arr = [
			'司令官以闲静为治事要则，闲静者，不亲小节之谓。',
			'目标不是都能达到的，但它可以作为瞄准点。',
			'有勇气并不表示恐惧不存在，而是敢面对恐惧克服恐惧。',
			'每个人的生命都是一只小船，梦想是小船的风帆。',
			'消沉与低谷终将过去，积极才是人生的主流。',
			'羡慕别人得到的，不如珍惜自己拥有的。',
			'思想如钻子，必须集中在一点钻下去才有力量。',
			'骏马是跑出来的，强兵是打出来的。',
			'你要做多大的事情，就该承受多大的压力。',
			'主宰命运的是人，我们不能被命运主宰。',
			'有志者自有千计万计，无志者只感千难万难。',
			'志不强者智不达，言不信者行不果。',
			'决定问题，需要智慧，贯彻执行时则需要耐心。',
			'最大的过失，就是错了不承认有错。',
			'只要一松懈，各种愚昧就会乘虚而入。',
			'人只要不失去方向，就不会失去自己。',
			'乐观地对待失败，成功就会向你招手。',
			'成功者学习别人的经验，一般人学习自己的经验。',
			'走错一步是遗憾，走错一生是悲剧。',
			'靠山山会倒，靠水水会流，靠自己永远不倒。',
			'通过辛勤的工作获得财富才是人生的大快事。',
			'思想如钻子，必须集中在一点钻下去才有力量。'
		]
		obj.Hellogreetings = arr[Math.floor(Math.random() * arr.length)];

		if (hour < 6) {
			obj.theme = uni.getStorageSync("FRAMEWORK_USERINFO_KEY").empname+' '+'凌晨好！'
			return obj
		} else if (hour < 9) {
			obj.theme =uni.getStorageSync("FRAMEWORK_USERINFO_KEY").empname+' '+'早上好！'
			return obj
		} else if (hour < 12) {
			obj.theme =uni.getStorageSync("FRAMEWORK_USERINFO_KEY").empname+' '+'上午好！'
			return obj
		} else if (hour < 14) {
			obj.theme =uni.getStorageSync("FRAMEWORK_USERINFO_KEY").empname+' '+'中午好！'
			return obj
		} else if (hour < 17) {
			obj.theme =uni.getStorageSync("FRAMEWORK_USERINFO_KEY").empname+' '+'下午好！'
			return obj
		} else if (hour < 19) {
			obj.theme =uni.getStorageSync("FRAMEWORK_USERINFO_KEY").empname+' '+'傍晚好！'
			return obj
		} else if (hour < 22) {
			obj.theme =uni.getStorageSync("FRAMEWORK_USERINFO_KEY").empname+' '+'晚上好！'
			return obj
		} else {
			obj.theme =uni.getStorageSync("FRAMEWORK_USERINFO_KEY").empname+' '+'晚上好！'
			return obj
		}
	},
    /*日期格式转换*/
    setCurrDate(currDate, type) {
        //var currDate = new Date();
        var currYear = currDate.getFullYear(),
            currMonth = currDate.getMonth() + 1,
            currDay = currDate.getDate(),
            currHoure = currDate.getHours(),
            currMin = currDate.getMinutes(),
        currSec = currDate.getSeconds();
        currMonth = currMonth < 10 ? "0" + currMonth : currMonth;
        currDay = currDay < 10 ? "0" + currDay : currDay;
        currHoure = currHoure < 10 ? "0" + currHoure : currHoure;
        currMin = currMin < 10 ? "0" + currMin : currMin;
        currSec = currSec < 10 ? "0" + currSec : currSec;
        var _retData = {};
        switch (type.toLocaleUpperCase()) {
            case "Y":
                _retData = {
                    retOne: currYear + "年",
                    retTwo: currYear
                };
                break;
            case "M":
                _retData = {
                    retOne: currMonth + "月",
                    retTwo: currMonth
                };
                break;
            case "D":
                _retData = {
                    retOne: currDay
                };
                break;
            case "YM":
                _retData = {
                    retOne: currYear + "年" + currMonth + "月",
                    retTwo: currYear + "-" + currMonth,
                    retThree: currYear + "/" + currMonth
                };
                break;
            case "YMD":
                _retData = {
                    retOne: currYear + "年" + currMonth + "月" + currDay + "日",
                    retTwo: currYear + "-" + currMonth + "-" + currDay,
                    retThree: currYear + "/" + currMonth + "/" + currDay
                };
                break;
            case "YMDH":
                _retData = {
                    retOne: currYear + "年" + currMonth + "月" + currDay + "日 " + currHoure + "时",
                    retTwo: currYear + "-" + currMonth + "-" + currDay + " " + currHoure,
                    retThree: currYear + "/" + currMonth + "/" + currDay + " " + currHoure
                }
                break;
            case "YMDHMS":
                _retData = {
                    retOne: currYear + "年" + currMonth + "月" + currDay + "日 " + currHoure + "时" + currMin + "分" + currSec + "秒",
                    retTwo: currYear + "-" + currMonth + "-" + currDay + " " + currHoure + ":" + currMin + ":" + currSec,
                    retThree: currYear + "/" + currMonth + "/" + currDay + " " + currHoure + ":" + currMin + ":" + currSec,
                };
                break;
            default:
                _retData = {
                    retOne: currDate
                };
                break;
        }
        return _retData;

    },
	//提示信息
	Tips(val){
		showModalWithCloseButton(val)
	},



}
